{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM docker-syncd-brcm-dnx-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get purge -y syncd

## Pre-install the fundamental packages
RUN apt-get update \
 && apt-get -y install  \
    net-tools           \
    python3-pip         \
    python3-dev         \
    python-is-python3   \
    python3-scapy       \
    build-essential     \
    libssl-dev          \
    libffi-dev          \
    wget                \
    cmake               \
    libnanomsg5         \
    libnanomsg-dev      \
    libthrift-0.17.0

{% if docker_syncd_brcm_dnx_rpc_debs.strip() -%}
# Copy locally-built Debian package dependencies
{{ copy_files("debs/", docker_syncd_brcm_dnx_rpc_debs.split(' '), "/debs/") }}
{% endif %}

{% if docker_syncd_brcm_dnx_rpc_pydebs.strip() -%}
# Copy locally-built Debian package dependencies
{{ copy_files("python-debs/", docker_syncd_brcm_dnx_rpc_pydebs.split(' '), "/debs/") }}
{% endif %}

{% if docker_syncd_brcm_dnx_rpc_debs.strip() -%}
# Install locally-built Debian packages and implicitly install their dependencies
{{ install_debian_packages(docker_syncd_brcm_dnx_rpc_debs.split(' ')) }}
{% endif %}

{% if docker_syncd_brcm_dnx_rpc_pydebs.strip() -%}
# Install locally-built Debian packages and implicitly install their dependencies
{{ install_debian_packages(docker_syncd_brcm_dnx_rpc_pydebs.split(' ')) }}
{% endif %}

RUN pip3 install cffi==1.16.0    \
 && pip3 install wheel  \
 && pip3 install nnpy   \
 && mkdir -p /opt       \
 && cd /opt             \
 && wget https://raw.githubusercontent.com/p4lang/ptf/master/ptf_nn/ptf_nn_agent.py \
 && apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y \
 && rm -rf /root/deps

COPY ["ptf_nn_agent.conf", "/etc/supervisor/conf.d/"]

## Clean up
RUN apt-get -y purge \
    cmake            \
    libssl-dev       \
    libffi-dev       \
    python3-dev      \
    python3-pip      \
    libthrift-dev    \
    build-essential

RUN apt-get clean -y && \
    apt-get autoclean -y && \
    apt-get autoremove -y && \
    rm -rf /debs

ENTRYPOINT ["/usr/local/bin/supervisord"]
